<template>
	<view class="ys">
		<view class="no-list" v-if="list.length == 0">
			暂无数据
		</view>
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="item">
				<view class="title">
					<text class="id">{{item.order_no}}</text>
					<text class="tips">{{item.status.text}}</text>
				</view>
				<view class="left">
					<view class="type">
						{{item.money}}元
					</view>
					<view class="time">
						{{item.create_time}}
					</view>

				</view>
			</view>
		</view>
		<view class="add" @click="pay">
			<image src="/static/image/jiaofei.svg" mode=""></image>
			<view class="">缴费</view>
		</view>
	</view>
</template>

<script>
	import {
		getTicketList,
		payTicket
	} from "@/api/staff.js"
	export default {
		data() {
			return {
				list: [],
				page: 1,
				last_page: 1
			}
		},
		onLoad() {
			this.getTicketList()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.getTicketList()
			}
		},
		methods: {
			getTicketList() {
				getTicketList({
					page: this.page
				}).then(res => {
					if (res.code == 0) {
						this.list = this.list.concat(res.data.data)
						this.last_page = res.data.last_page
					}
				})
			},
			pay() {
				let that = this
				payTicket().then(res => {
					if (res.code == 0) {
						if (res.data.unifiedorder) {
							//拉起支付
							let paymentData = res.data.unifiedorder
							uni.requestPayment({
								timeStamp: paymentData.timeStamp,
								nonceStr: paymentData.nonceStr,
								package: "prepay_id=" + paymentData.prepay_id,
								signType: 'MD5',
								paySign: paymentData.paySign,
								success: function(result) {
									uni.$showMsg(result.message)
									item.show_pay = res.data.result.show_pay
									item.status = res.data.result.status
								},
								fail: function(err) {
									that.loading = false
								}
							})
						} else {
							uni.$showMsg(res.msg)
							setTimeout(() => {
								that.getTicketList()
							})
						}
					} else {
						uni.$showMsg(res.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.add {
		position: fixed;
		z-index: 1005;
		right: 0;
		bottom: 10%;

		image {
			width: 40px;
			height: 40px;
		}
	}

	.list {
		padding: 10px;
		box-sizing: border-box;

		.item {
			background: #fff;
			border-radius: 7px;
			padding: 10px;
			box-sizing: border-box;

			.title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 14px;
				padding-bottom: 10px;
				border-bottom: 1px solid #eee;

				.id {
					font-weight: bold;
				}

				.tips {
					font-size: 12px;
				}
			}

			.type {
				padding: 10px 0;
			}

			.time {
				padding-bottom: 10px;
				color: #777;
				font-size: 12px;
			}

			.btns {
				display: flex;
				justify-content: flex-end;
				border-top: 1px solid #eee;
				padding-top: 10px;

				button {
					font-size: 12px;
					margin: 0;
					padding: 0;
					width: 50px;
					background: $uni-bg-color;
					color: #fff;
				}
			}
		}
	}
</style>